package com.xhd.base.obj;

import java.util.HashMap;

import com.xhd.base.log.Log;
import com.xhd.base.log.LogFactory;
import com.xhd.base.util.xBaseObj;
import com.xhd.cache.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class EnpObjClass implements UseCache {


	  private Class jm204 = null;
	  private HashMap jm205 = null;
	  private String jm21 = null;
	  private String jm206 = null;
	  private HashMap jm207 = null;
	  private HashMap jm208 = new HashMap(2);
	  private Method jm209 = null;
	  private static HashMap jm26 = new HashMap(256);
	  private static boolean jm158 = false;
	  private static final Log logobj;
	  static Class objclass;

	  static
	  {
	    Class tempobjclass = objclass;
	    if (tempobjclass == null)
	    {
	      ;
	      try
	      {
	    	  EnpObjClass.objclass = Class.forName("com.sinocc.base.config.EnpObjClass");
	      }
	      catch (ClassNotFoundException localClassNotFoundException)
	      {
	        throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
	      }
	    }
	    logobj = LogFactory.getLog(tempobjclass);
	  }

	  private EnpObjClass(Class paramClass)
	  {
	    jm124(paramClass);
	    if (jm158)
	      return;
	    jm158 = true;
	    CacheMgr.registerCache(this);
	  }

	  public static EnpObjClass getInstance(Class paramClass)
	  {
	    EnpObjClass localEnpObjClass = (EnpObjClass)jm26.get(paramClass);
	    if (localEnpObjClass == null)
	      if (paramClass != null)
	      {
	        localEnpObjClass = new EnpObjClass(paramClass);
	        jm26.put(paramClass, localEnpObjClass);
	      }
	      else
	      {
	        logobj.error("Class can't null.");
	      }
	    return localEnpObjClass;
	  }

	  public static EnpObjClass getInstance(String paramString)
	  {
	    int i = paramString.indexOf(32);
	    if (i > 0)
	      paramString = paramString.substring(0, i);
	    Class localClass = EnpObjFactory.getInstance().getBizClass(paramString);
	    if (localClass == null)
	    {
	      if (paramString.startsWith("user_"))
	        return null;
	      return null;
	    }
	    return getInstance(localClass);
	  }

	  public static EnpObjClass getInstance(Object paramObject)
	  {
	    EnpObjClass localEnpObjClass = (EnpObjClass)jm26.get(paramObject.getClass());
	    if (localEnpObjClass == null)
	    {
	      localEnpObjClass = new EnpObjClass(paramObject.getClass());
	      jm26.put(paramObject.getClass(), localEnpObjClass);
	    }
	    return localEnpObjClass;
	  }

	  private void jm124(Class paramClass)
	  {
	    this.jm206 = paramClass.getName();
	    int i = this.jm206.lastIndexOf(46);
	    if (i > 0)
	      this.jm21 = this.jm206.substring(i + 1).toLowerCase();
	    else
	      this.jm21 = this.jm206.toLowerCase();
	    this.jm204 = paramClass;
	      Field[] arrayOfField = this.jm204.getFields();
	    HashMap localHashMap = new HashMap(arrayOfField.length + 1);
	    localHashMap.put("_all_", arrayOfField);
	    for (int j = 0; j < arrayOfField.length; ++j)
	      localHashMap.put(arrayOfField[j].getName().toLowerCase(), arrayOfField[j]);
	    this.jm205 = localHashMap;
	    localHashMap = null;
	     Method[] arrayOfMethod = this.jm204.getMethods();
	    int k = (arrayOfMethod == null) ? 0 : arrayOfMethod.length;
	    this.jm207 = new HashMap(k);
	    for (int l = 0; l < k; ++l)
	    {
	      String str = arrayOfMethod[l].getName().toLowerCase();
	      if (!(str.startsWith("do")))
	        continue;
	      Class[] arrayOfClass = arrayOfMethod[l].getParameterTypes();
	      if ((arrayOfClass == null) || (arrayOfClass.length == 0))
	      {
	        this.jm207.put(str, arrayOfMethod[l]);
	      }
	      else
	      {
	        if ((1 != arrayOfClass.length) || (!(str.equals("dotransaction"))))
	          continue;
	        this.jm209 = arrayOfMethod[l];
	      }
	    }
	  }

	  public String getName()
	  {
	    return this.jm21;
	  }

	  public String getFullName()
	  {
	    return this.jm206;
	  }

	  public static String getObjName(Object paramObject)
	  {
	    String str = paramObject.getClass().getName();
	    int i = str.lastIndexOf(46);
	    if (i > 0)
	      str = str.substring(i + 1);
	    return str.toLowerCase();
	  }

	  public Class getBizClass()
	  {
	    return this.jm204;
	  }

	  public Field getField(String paramString)
	  {
	    return ((Field)this.jm205.get(paramString.toLowerCase()));
	  }

	  public Field[] getFields()
	  {
	    return ((Field[])this.jm205.get("_all_"));
	  }

	  public boolean isString(Field paramField)
	  {
	    String str = paramField.getType().getName();
	    return str.endsWith(".String");
	  }

	  public boolean isNumber(Field paramField)
	  {
	    String str = paramField.getType().getName();
	    return (("int".equals(str)) || (str.endsWith("BigDecimal")));
	  }

	  public String findKeyField(String paramString)
	  {
	    String str = this.jm21;
	    if (this.jm21.indexOf("_") > 0)
	      paramString = "_" + paramString;
	    for (int i = 0; i < 5; ++i)
	    {
	      str = str.substring(1);
	      if (this.jm205.containsKey(str + paramString))
	        return str + paramString;
	      if (str.length() < 1)
	        break;
	    }
	    return null;
	  }

	  public Method getActionMethod(String paramString)
	  {
	    return ((Method)this.jm207.get("do" + paramString));
	  }

	  public Method getActionsMethod()
	  {
	    return this.jm209;
	  }

	  public Method getEventMethod(String paramString)
	  {
	    if (this.jm208.containsKey(paramString))
	      return ((Method)this.jm208.get(paramString));
	    Method[] arrayOfMethod = this.jm204.getMethods();
	    int i = (arrayOfMethod == null) ? 0 : arrayOfMethod.length;
	    for (int j = 0; j < i; ++j)
	    {
	      String str = arrayOfMethod[j].getName().toLowerCase();
	      if (!(str.equals(paramString)))
	        continue;
	      this.jm208.put(paramString, arrayOfMethod[j]);
	      return arrayOfMethod[j];
	    }
	    this.jm208.put(paramString, null);
	    return null;
	  }

	  public boolean clearCache()
	  {
	    jm26.clear();
	    return true;
	  }

	  public int cacheSize()
	  {
	    return jm26.size();
	  }

	  public Object cacheData()
	  {
	    return jm26;
	  }

	
}
